//
//  MyFocusCell.m
//  唧歪
//
//  Created by ZC on 15/9/2.
//  Copyright (c) 2015年 MWJ. All rights reserved.
//

#import "MyFocusCell.h"
#import "AppDelegate.h"
#define myFocuscancelURL @"https://app.jiwaipro.com:8888/index.php/JiWai/cancelfocus"
#define myFocusURL @"https://app.jiwaipro.com:8888/index.php/JiWai/focus"


@implementation MyFocusCell{
    AppDelegate *app;
    NSString *focusStr;
}

- (void)awakeFromNib {
    app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (IBAction)switchAction:(id)sender {
    
    if ([self.focus isOn]) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示:" message:@"您已关注此用户" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        
        NSString *string = [NSString stringWithFormat:@"myuser_id=%@&heuser_id=%@",app.user_id,self.user_id];
        [self focusPath:myFocusURL Str:string];
        
    }else{
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示:" message:@"您已取消关注此用户" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        
        NSString *string = [NSString stringWithFormat:@"myuser_id=%@&heuser_id=%@",app.user_id,self.user_id];
        [self focusPath:myFocuscancelURL Str:string];
    }
    
}
-(void)focusPath:(NSString *)path Str:(NSString *)string{
    NSURL *url = [NSURL URLWithString:path];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        focusStr =[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        [self performSelectorOnMainThread:@selector(focusData) withObject:focusStr waitUntilDone:YES];
    }];
}
-(void)focusData{
}
@end
